home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / File.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  10.5 KB  |  631 lines

  1. package java.io;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URI;
  5. import java.net.URISyntaxException;
  6. import java.net.URL;
  7. import java.security.AccessControlException;
  8. import java.security.AccessController;
  9. import java.util.ArrayList;
  10. import java.util.Random;
  11. import sun.misc.SharedSecrets;
  12. import sun.security.action.GetPropertyAction;
  13.  
  14. public class File implements Serializable, Comparable<File> {
  15.    // $FF: renamed from: fs java.io.FileSystem
  16.    private static FileSystem field_0 = FileSystem.getFileSystem();
  17.    private String path;
  18.    private transient int prefixLength;
  19.    public static final char separatorChar;
  20.    public static final String separator;
  21.    public static final char pathSeparatorChar;
  22.    public static final String pathSeparator;
  23.    private static final Object tmpFileLock;
  24.    private static int counter;
  25.    private static String tmpdir;
  26.    private static final long serialVersionUID = 301077366599181567L;
  27.  
  28.    int getPrefixLength() {
  29.       return this.prefixLength;
  30.    }
  31.  
  32.    private File(String var1, int var2) {
  33.       this.path = var1;
  34.       this.prefixLength = var2;
  35.    }
  36.  
  37.    private File(String var1, File var2) {
  38.       assert var2.path != null;
  39.  
  40.       assert !var2.path.equals("");
  41.  
  42.       this.path = field_0.resolve(var2.path, var1);
  43.       this.prefixLength = var2.prefixLength;
  44.    }
  45.  
  46.    public File(String var1) {
  47.       if (var1 == null) {
  48.          throw new NullPointerException();
  49.       } else {
  50.          this.path = field_0.normalize(var1);
  51.          this.prefixLength = field_0.prefixLength(this.path);
  52.       }
  53.    }
  54.  
  55.    public File(String var1, String var2) {
  56.       if (var2 == null) {
  57.          throw new NullPointerException();
  58.       } else {
  59.          if (var1 != null) {
  60.             if (var1.equals("")) {
  61.                this.path = field_0.resolve(field_0.getDefaultParent(), field_0.normalize(var2));
  62.             } else {
  63.                this.path = field_0.resolve(field_0.normalize(var1), field_0.normalize(var2));
  64.             }
  65.          } else {
  66.             this.path = field_0.normalize(var2);
  67.          }
  68.  
  69.          this.prefixLength = field_0.prefixLength(this.path);
  70.       }
  71.    }
  72.  
  73.    public File(File var1, String var2) {
  74.       if (var2 == null) {
  75.          throw new NullPointerException();
  76.       } else {
  77.          if (var1 != null) {
  78.             if (var1.path.equals("")) {
  79.                this.path = field_0.resolve(field_0.getDefaultParent(), field_0.normalize(var2));
  80.             } else {
  81.                this.path = field_0.resolve(var1.path, field_0.normalize(var2));
  82.             }
  83.          } else {
  84.             this.path = field_0.normalize(var2);
  85.          }
  86.  
  87.          this.prefixLength = field_0.prefixLength(this.path);
  88.       }
  89.    }
  90.  
  91.    public File(URI var1) {
  92.       if (!var1.isAbsolute()) {
  93.          throw new IllegalArgumentException("URI is not absolute");
  94.       } else if (var1.isOpaque()) {
  95.          throw new IllegalArgumentException("URI is not hierarchical");
  96.       } else {
  97.          String var2 = var1.getScheme();
  98.          if (var2 != null && var2.equalsIgnoreCase("file")) {
  99.             if (var1.getAuthority() != null) {
  100.                throw new IllegalArgumentException("URI has an authority component");
  101.             } else if (var1.getFragment() != null) {
  102.                throw new IllegalArgumentException("URI has a fragment component");
  103.             } else if (var1.getQuery() != null) {
  104.                throw new IllegalArgumentException("URI has a query component");
  105.             } else {
  106.                String var3 = var1.getPath();
  107.                if (var3.equals("")) {
  108.                   throw new IllegalArgumentException("URI path component is empty");
  109.                } else {
  110.                   var3 = field_0.fromURIPath(var3);
  111.                   if (separatorChar != '/') {
  112.                      var3 = var3.replace('/', separatorChar);
  113.                   }
  114.  
  115.                   this.path = field_0.normalize(var3);
  116.                   this.prefixLength = field_0.prefixLength(this.path);
  117.                }
  118.             }
  119.          } else {
  120.             throw new IllegalArgumentException("URI scheme is not \"file\"");
  121.          }
  122.       }
  123.    }
  124.  
  125.    public String getName() {
  126.       int var1 = this.path.lastIndexOf(separatorChar);
  127.       return var1 < this.prefixLength ? this.path.substring(this.prefixLength) : this.path.substring(var1 + 1);
  128.    }
  129.  
  130.    public String getParent() {
  131.       int var1 = this.path.lastIndexOf(separatorChar);
  132.       if (var1 < this.prefixLength) {
  133.          return this.prefixLength > 0 && this.path.length() > this.prefixLength ? this.path.substring(0, this.prefixLength) : null;
  134.       } else {
  135.          return this.path.substring(0, var1);
  136.       }
  137.    }
  138.  
  139.    public File getParentFile() {
  140.       String var1 = this.getParent();
  141.       return var1 == null ? null : new File(var1, this.prefixLength);
  142.    }
  143.  
  144.    public String getPath() {
  145.       return this.path;
  146.    }
  147.  
  148.    public boolean isAbsolute() {
  149.       return field_0.isAbsolute(this);
  150.    }
  151.  
  152.    public String getAbsolutePath() {
  153.       return field_0.resolve(this);
  154.    }
  155.  
  156.    public File getAbsoluteFile() {
  157.       String var1 = this.getAbsolutePath();
  158.       return new File(var1, field_0.prefixLength(var1));
  159.    }
  160.  
  161.    public String getCanonicalPath() throws IOException {
  162.       return field_0.canonicalize(field_0.resolve(this));
  163.    }
  164.  
  165.    public File getCanonicalFile() throws IOException {
  166.       String var1 = this.getCanonicalPath();
  167.       return new File(var1, field_0.prefixLength(var1));
  168.    }
  169.  
  170.    private static String slashify(String var0, boolean var1) {
  171.       String var2 = var0;
  172.       if (separatorChar != '/') {
  173.          var2 = var0.replace(separatorChar, '/');
  174.       }
  175.  
  176.       if (!var2.startsWith("/")) {
  177.          var2 = "/" + var2;
  178.       }
  179.  
  180.       if (!var2.endsWith("/") && var1) {
  181.          var2 = var2 + "/";
  182.       }
  183.  
  184.       return var2;
  185.    }
  186.  
  187.    /** @deprecated */
  188.    @Deprecated
  189.    public URL toURL() throws MalformedURLException {
  190.       return new URL("file", "", slashify(this.getAbsolutePath(), this.isDirectory()));
  191.    }
  192.  
  193.    public URI toURI() {
  194.       try {
  195.          File var1 = this.getAbsoluteFile();
  196.          String var2 = slashify(var1.getPath(), var1.isDirectory());
  197.          if (var2.startsWith("//")) {
  198.             var2 = "//" + var2;
  199.          }
  200.  
  201.          return new URI("file", (String)null, var2, (String)null);
  202.       } catch (URISyntaxException var3) {
  203.          throw new Error(var3);
  204.       }
  205.    }
  206.  
  207.    public boolean canRead() {
  208.       SecurityManager var1 = System.getSecurityManager();
  209.       if (var1 != null) {
  210.          var1.checkRead(this.path);
  211.       }
  212.  
  213.       return field_0.checkAccess(this, 4);
  214.    }
  215.  
  216.    public boolean canWrite() {
  217.       SecurityManager var1 = System.getSecurityManager();
  218.       if (var1 != null) {
  219.          var1.checkWrite(this.path);
  220.       }
  221.  
  222.       return field_0.checkAccess(this, 2);
  223.    }
  224.  
  225.    public boolean exists() {
  226.       SecurityManager var1 = System.getSecurityManager();
  227.       if (var1 != null) {
  228.          var1.checkRead(this.path);
  229.       }
  230.  
  231.       return (field_0.getBooleanAttributes(this) & 1) != 0;
  232.    }
  233.  
  234.    public boolean isDirectory() {
  235.       SecurityManager var1 = System.getSecurityManager();
  236.       if (var1 != null) {
  237.          var1.checkRead(this.path);
  238.       }
  239.  
  240.       return (field_0.getBooleanAttributes(this) & 4) != 0;
  241.    }
  242.  
  243.    public boolean isFile() {
  244.       SecurityManager var1 = System.getSecurityManager();
  245.       if (var1 != null) {
  246.          var1.checkRead(this.path);
  247.       }
  248.  
  249.       return (field_0.getBooleanAttributes(this) & 2) != 0;
  250.    }
  251.  
  252.    public boolean isHidden() {
  253.       SecurityManager var1 = System.getSecurityManager();
  254.       if (var1 != null) {
  255.          var1.checkRead(this.path);
  256.       }
  257.  
  258.       return (field_0.getBooleanAttributes(this) & 8) != 0;
  259.    }
  260.  
  261.    public long lastModified() {
  262.       SecurityManager var1 = System.getSecurityManager();
  263.       if (var1 != null) {
  264.          var1.checkRead(this.path);
  265.       }
  266.  
  267.       return field_0.getLastModifiedTime(this);
  268.    }
  269.  
  270.    public long length() {
  271.       SecurityManager var1 = System.getSecurityManager();
  272.       if (var1 != null) {
  273.          var1.checkRead(this.path);
  274.       }
  275.  
  276.       return field_0.getLength(this);
  277.    }
  278.  
  279.    public boolean createNewFile() throws IOException {
  280.       SecurityManager var1 = System.getSecurityManager();
  281.       if (var1 != null) {
  282.          var1.checkWrite(this.path);
  283.       }
  284.  
  285.       return field_0.createFileExclusively(this.path);
  286.    }
  287.  
  288.    public boolean delete() {
  289.       SecurityManager var1 = System.getSecurityManager();
  290.       if (var1 != null) {
  291.          var1.checkDelete(this.path);
  292.       }
  293.  
  294.       return field_0.delete(this);
  295.    }
  296.  
  297.    public void deleteOnExit() {
  298.       SecurityManager var1 = System.getSecurityManager();
  299.       if (var1 != null) {
  300.          var1.checkDelete(this.path);
  301.       }
  302.  
  303.       DeleteOnExitHook.add(this.path);
  304.    }
  305.  
  306.    public String[] list() {
  307.       SecurityManager var1 = System.getSecurityManager();
  308.       if (var1 != null) {
  309.          var1.checkRead(this.path);
  310.       }
  311.  
  312.       return field_0.list(this);
  313.    }
  314.  
  315.    public String[] list(FilenameFilter var1) {
  316.       String[] var2 = this.list();
  317.       if (var2 != null && var1 != null) {
  318.          ArrayList var3 = new ArrayList();
  319.  
  320.          for(int var4 = 0; var4 < var2.length; ++var4) {
  321.             if (var1.accept(this, var2[var4])) {
  322.                var3.add(var2[var4]);
  323.             }
  324.          }
  325.  
  326.          return (String[])var3.toArray(new String[var3.size()]);
  327.       } else {
  328.          return var2;
  329.       }
  330.    }
  331.  
  332.    public File[] listFiles() {
  333.       String[] var1 = this.list();
  334.       if (var1 == null) {
  335.          return null;
  336.       } else {
  337.          int var2 = var1.length;
  338.          File[] var3 = new File[var2];
  339.  
  340.          for(int var4 = 0; var4 < var2; ++var4) {
  341.             var3[var4] = new File(var1[var4], this);
  342.          }
  343.  
  344.          return var3;
  345.       }
  346.    }
  347.  
  348.    public File[] listFiles(FilenameFilter var1) {
  349.       String[] var2 = this.list();
  350.       if (var2 == null) {
  351.          return null;
  352.       } else {
  353.          ArrayList var3 = new ArrayList();
  354.  
  355.          for(int var4 = 0; var4 < var2.length; ++var4) {
  356.             if (var1 == null || var1.accept(this, var2[var4])) {
  357.                var3.add(new File(var2[var4], this));
  358.             }
  359.          }
  360.  
  361.          return (File[])var3.toArray(new File[var3.size()]);
  362.       }
  363.    }
  364.  
  365.    public File[] listFiles(FileFilter var1) {
  366.       String[] var2 = this.list();
  367.       if (var2 == null) {
  368.          return null;
  369.       } else {
  370.          ArrayList var3 = new ArrayList();
  371.  
  372.          for(int var4 = 0; var4 < var2.length; ++var4) {
  373.             File var5 = new File(var2[var4], this);
  374.             if (var1 == null || var1.accept(var5)) {
  375.                var3.add(var5);
  376.             }
  377.          }
  378.  
  379.          return (File[])var3.toArray(new File[var3.size()]);
  380.       }
  381.    }
  382.  
  383.    public boolean mkdir() {
  384.       SecurityManager var1 = System.getSecurityManager();
  385.       if (var1 != null) {
  386.          var1.checkWrite(this.path);
  387.       }
  388.  
  389.       return field_0.createDirectory(this);
  390.    }
  391.  
  392.    public boolean mkdirs() {
  393.       if (this.exists()) {
  394.          return false;
  395.       } else if (this.mkdir()) {
  396.          return true;
  397.       } else {
  398.          File var1 = null;
  399.  
  400.          try {
  401.             var1 = this.getCanonicalFile();
  402.          } catch (IOException var3) {
  403.             return false;
  404.          }
  405.  
  406.          String var2 = var1.getParent();
  407.          return var2 != null && (new File(var2, field_0.prefixLength(var2))).mkdirs() && var1.mkdir();
  408.       }
  409.    }
  410.  
  411.    public boolean renameTo(File var1) {
  412.       SecurityManager var2 = System.getSecurityManager();
  413.       if (var2 != null) {
  414.          var2.checkWrite(this.path);
  415.          var2.checkWrite(var1.path);
  416.       }
  417.  
  418.       return field_0.rename(this, var1);
  419.    }
  420.  
  421.    public boolean setLastModified(long var1) {
  422.       if (var1 < 0L) {
  423.          throw new IllegalArgumentException("Negative time");
  424.       } else {
  425.          SecurityManager var3 = System.getSecurityManager();
  426.          if (var3 != null) {
  427.             var3.checkWrite(this.path);
  428.          }
  429.  
  430.          return field_0.setLastModifiedTime(this, var1);
  431.       }
  432.    }
  433.  
  434.    public boolean setReadOnly() {
  435.       SecurityManager var1 = System.getSecurityManager();
  436.       if (var1 != null) {
  437.          var1.checkWrite(this.path);
  438.       }
  439.  
  440.       return field_0.setReadOnly(this);
  441.    }
  442.  
  443.    public boolean setWritable(boolean var1, boolean var2) {
  444.       SecurityManager var3 = System.getSecurityManager();
  445.       if (var3 != null) {
  446.          var3.checkWrite(this.path);
  447.       }
  448.  
  449.       return field_0.setPermission(this, 2, var1, var2);
  450.    }
  451.  
  452.    public boolean setWritable(boolean var1) {
  453.       return this.setWritable(var1, true);
  454.    }
  455.  
  456.    public boolean setReadable(boolean var1, boolean var2) {
  457.       SecurityManager var3 = System.getSecurityManager();
  458.       if (var3 != null) {
  459.          var3.checkWrite(this.path);
  460.       }
  461.  
  462.       return field_0.setPermission(this, 4, var1, var2);
  463.    }
  464.  
  465.    public boolean setReadable(boolean var1) {
  466.       return this.setReadable(var1, true);
  467.    }
  468.  
  469.    public boolean setExecutable(boolean var1, boolean var2) {
  470.       SecurityManager var3 = System.getSecurityManager();
  471.       if (var3 != null) {
  472.          var3.checkWrite(this.path);
  473.       }
  474.  
  475.       return field_0.setPermission(this, 1, var1, var2);
  476.    }
  477.  
  478.    public boolean setExecutable(boolean var1) {
  479.       return this.setExecutable(var1, true);
  480.    }
  481.  
  482.    public boolean canExecute() {
  483.       SecurityManager var1 = System.getSecurityManager();
  484.       if (var1 != null) {
  485.          var1.checkExec(this.path);
  486.       }
  487.  
  488.       return field_0.checkAccess(this, 1);
  489.    }
  490.  
  491.    public static File[] listRoots() {
  492.       return field_0.listRoots();
  493.    }
  494.  
  495.    public long getTotalSpace() {
  496.       SecurityManager var1 = System.getSecurityManager();
  497.       if (var1 != null) {
  498.          var1.checkPermission(new RuntimePermission("getFileSystemAttributes"));
  499.          var1.checkRead(this.path);
  500.       }
  501.  
  502.       return field_0.getSpace(this, 0);
  503.    }
  504.  
  505.    public long getFreeSpace() {
  506.       SecurityManager var1 = System.getSecurityManager();
  507.       if (var1 != null) {
  508.          var1.checkPermission(new RuntimePermission("getFileSystemAttributes"));
  509.          var1.checkRead(this.path);
  510.       }
  511.  
  512.       return field_0.getSpace(this, 1);
  513.    }
  514.  
  515.    public long getUsableSpace() {
  516.       SecurityManager var1 = System.getSecurityManager();
  517.       if (var1 != null) {
  518.          var1.checkPermission(new RuntimePermission("getFileSystemAttributes"));
  519.          var1.checkRead(this.path);
  520.       }
  521.  
  522.       return field_0.getSpace(this, 2);
  523.    }
  524.  
  525.    private static File generateFile(String var0, String var1, File var2) throws IOException {
  526.       if (counter == -1) {
  527.          counter = (new Random()).nextInt() & '\uffff';
  528.       }
  529.  
  530.       ++counter;
  531.       return new File(var2, var0 + Integer.toString(counter) + var1);
  532.    }
  533.  
  534.    private static String getTempDir() {
  535.       if (tmpdir == null) {
  536.          GetPropertyAction var0 = new GetPropertyAction("java.io.tmpdir");
  537.          tmpdir = (String)AccessController.doPrivileged(var0);
  538.          tmpdir = field_0.normalize(tmpdir);
  539.       }
  540.  
  541.       return tmpdir;
  542.    }
  543.  
  544.    private static boolean checkAndCreate(String var0, SecurityManager var1) throws IOException {
  545.       if (var1 != null) {
  546.          try {
  547.             var1.checkWrite(var0);
  548.          } catch (AccessControlException var3) {
  549.             throw new SecurityException("Unable to create temporary file");
  550.          }
  551.       }
  552.  
  553.       return field_0.createFileExclusively(var0);
  554.    }
  555.  
  556.    public static File createTempFile(String var0, String var1, File var2) throws IOException {
  557.       if (var0 == null) {
  558.          throw new NullPointerException();
  559.       } else if (var0.length() < 3) {
  560.          throw new IllegalArgumentException("Prefix string too short");
  561.       } else {
  562.          String var3 = var1 == null ? ".tmp" : var1;
  563.          synchronized(tmpFileLock) {
  564.             if (var2 == null) {
  565.                String var5 = getTempDir();
  566.                var2 = new File(var5, field_0.prefixLength(var5));
  567.             }
  568.  
  569.             SecurityManager var9 = System.getSecurityManager();
  570.  
  571.             File var6;
  572.             do {
  573.                var6 = generateFile(var0, var3, var2);
  574.             } while(!checkAndCreate(var6.getPath(), var9));
  575.  
  576.             return var6;
  577.          }
  578.       }
  579.    }
  580.  
  581.    public static File createTempFile(String var0, String var1) throws IOException {
  582.       return createTempFile(var0, var1, (File)null);
  583.    }
  584.  
  585.    public int compareTo(File var1) {
  586.       return field_0.compare(this, var1);
  587.    }
  588.  
  589.    public boolean equals(Object var1) {
  590.       if (var1 != null && var1 instanceof File) {
  591.          return this.compareTo((File)var1) == 0;
  592.       } else {
  593.          return false;
  594.       }
  595.    }
  596.  
  597.    public int hashCode() {
  598.       return field_0.hashCode(this);
  599.    }
  600.  
  601.    public String toString() {
  602.       return this.getPath();
  603.    }
  604.  
  605.    private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
  606.       var1.defaultWriteObject();
  607.       var1.writeChar(separatorChar);
  608.    }
  609.  
  610.    private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  611.       var1.defaultReadObject();
  612.       char var2 = var1.readChar();
  613.       if (var2 != separatorChar) {
  614.          this.path = this.path.replace(var2, separatorChar);
  615.       }
  616.  
  617.       this.path = field_0.normalize(this.path);
  618.       this.prefixLength = field_0.prefixLength(this.path);
  619.    }
  620.  
  621.    static {
  622.       separatorChar = field_0.getSeparator();
  623.       separator = "" + separatorChar;
  624.       pathSeparatorChar = field_0.getPathSeparator();
  625.       pathSeparator = "" + pathSeparatorChar;
  626.       tmpFileLock = new Object();
  627.       counter = -1;
  628.       SharedSecrets.setJavaIODeleteOnExitAccess(new 1());
  629.    }
  630. }
  631.